/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springblade.modules.admin.entity.EstateBuilding;
import org.springblade.modules.admin.vo.EstateBuildingDeptVO;
import org.springblade.modules.admin.vo.EstateBuildingVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.modules.admin.vo.EstateElevatorVO;
import org.springblade.modules.admin.vo.MaintainPlanContentVO;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 物业项目表 Mapper 接口
 *
 * @author ysq
 * @since 2022-05-27
 */
public interface EstateBuildingMapper extends BaseMapper<EstateBuilding> {

	/**
	 * 自定义分页
	 *
	 * @param page
	 * @param estateBuilding
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<EstateBuildingVO> selectEstateBuildingPage(@Param("page") IPage page, @Param("estateBuilding") EstateBuildingVO estateBuilding);

	/**
	 * 详情
	 * @param id
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	EstateBuildingVO detail(@Param("id") Long id, @Param("tenantId") String tenantId);

	/**
	 * 项目名称下拉选择数据
	 * @param tenantId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<Map<String, Object>> selectName(@Param("tenantId") String tenantId);

	/**
	 * 所属机构名称下拉选择数据
	 * @param tenantId
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	List<Map<String, Object>> selectDept(@Param("tenantId") String tenantId);

	/**
	 * 根据项目id查询所属机构
	 * @param buildingId 项目id
	 * @param tenantId 租户id
	 * @return
	 */
	@InterceptorIgnore(tenantLine = "on")
	EstateBuildingDeptVO selectDeptByBuildingId(@Param("buildingId") Long buildingId, @Param("tenantId") String tenantId);

	/**
	 * 根据id查询物业项目详情
	 * @param id
	 * @return
	 */
	EstateBuildingVO selectEstateBuildingById(Long id);

	@Select("SELECT DISTINCT COUNT(DISTINCT eb.tenant_id) FROM blade_elevator_device ed INNER JOIN blade_elevator e ON e.id=ed.elevator_id INNER JOIN blade_building b ON b.id=e.building_id INNER JOIN blade_estate_building eb ON eb.building_id=b.id WHERE ed.`status`=1 AND ed.device_id IS NOT NULL AND e.`status`=1 AND b.`status`=1 AND eb.`status`=1 AND e.is_deleted = 0 AND b.is_deleted = 0 AND eb.is_deleted = 0")
    Integer estateCompanyCountStatistics();

	@InterceptorIgnore(tenantLine = "on")
    List<MaintainPlanContentVO> estateMalElevatorPlanList(@Param("tenantId") String tenantId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

	@InterceptorIgnore(tenantLine = "on")
	List<EstateElevatorVO> estateElevatorList(@Param("tenantId") String tenantId);
}
